package cn.darkhorse.device.service.impl;

import cn.darkhorse.device.pojo.MesThirdPartyData;
import cn.darkhorse.device.mapper.MesThirdPartyDataMapper;
import cn.darkhorse.device.service.MesThirdPartyDataService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author maoguanjun
 * @since 2023-11-09
 */
@Service
public class MesThirdPartyDataServiceImpl extends ServiceImpl<MesThirdPartyDataMapper, MesThirdPartyData> implements MesThirdPartyDataService {

    @Autowired
    private MesThirdPartyDataService mesThirdPartyDataService;

    @Override
    public AjaxResult add(MesThirdPartyData mesThirdPartyData) {
        LambdaQueryWrapper<MesThirdPartyData> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(mesThirdPartyData.getName())) {
            queryWrapper.eq(MesThirdPartyData::getName, mesThirdPartyData.getName());
            MesThirdPartyData mesThirdPartyDataVo = mesThirdPartyDataService.getOne(queryWrapper);
            if (Objects.nonNull(mesThirdPartyDataVo)) {
                return AjaxResult.error("第三方名称重复！");
            }
            save(mesThirdPartyData);
            return AjaxResult.success();

        }
        return null;
    }
}
